 <template>
   <el-card shadow="always" class="box-card">
      <div class="card-name search-item">
        <div class="name width2">库存盘点</div>
        <div class="mr-15">
          <el-button size="medium" type="primary">导出系统库存</el-button>
          <el-button size="medium" type="danger">生成盘点单据</el-button>
        </div>
      </div>
      <div class="content-con">
        <el-form :model="form" ref="form" size="medium">
          <el-row type="flex" justify="start">
            <el-col :span="4">
              <el-form-item prop="warehouse" class="item-padding">
                <el-select v-model="form.warehouse" clearable placeholder="所有仓库" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in wareList"
                    :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="warehouse" class="item-padding">
                <el-select v-model="form.goods_type" clearable placeholder="所有类别" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in typeList"
                    :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="goods" class="item-padding">
                <div class="flex-s">
                  <span>商品：</span>
                  <div><el-input v-model="form.goods" clearable  placeholder="商品"></el-input></div>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="zero_stock">
                <el-checkbox v-model="form.zero_stock">零库存</el-checkbox>
                <el-button class="btn-green" @click="search">查 询</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <!-- 表格 -->
        <div class="bank-form">
          <div class="form-item">
            <el-table
              :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              class="table"
              stripe border
              :header-cell-style="{background:'#f3f3f3',textAlign: 'center'}"
              :cell-style="{ textAlign: 'center' }"><!--:data="用于存放请求数据回来的数组" -->
              <el-table-column prop="warehouse" label="仓库" width="140">
              </el-table-column>
              <el-table-column prop="goods_type" label="商品类别" width="120">
              </el-table-column>
              <el-table-column prop="goods_no" label="商品编号" width="180">
              </el-table-column>
              <el-table-column prop="goods_name" label="商品名称" width="140">
              </el-table-column>
              <el-table-column prop="model" label="规格型号" width="120">
              </el-table-column>
              <el-table-column prop="unit" label="单位" width="140">
              </el-table-column>
              <el-table-column prop="safe_stock" label="安全库存" width="150">
              </el-table-column>
              <el-table-column prop="system_stock" label="系统库存" width="150">
              </el-table-column>
              <el-table-column prop="check_stock" label="盘点库存" width="200">
              </el-table-column>
              <el-table-column prop="stock_surplus_losses" label="盘盈盘亏" width="200">
              </el-table-column>
            </el-table>
          </div>
          <!-- 分页-页码 -->
          <div class="page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="tableData.length">
            </el-pagination>
          </div>
        </div>
      </div>
   </el-card>

 </template>
<script>

export default {
  data () {
    return {
      currentPage: 1, //当前页码
      pagesize: 5,    //每页的数据条数
      //tableData: [], //表格数据
      form: {
        warehouse: '0',
        goods_type: '',
        goods: '',
        zero_stock: false
      },
      wareList: [
        {value: '0',label:'所有仓库'}
      ],
      typeList: [
        {value: '0',label: '所有类别'},
        {value: '1',label: '浆果'},
        {value: '2',label: '柑橘属'}
      ],
      tableData: [
        {
          warehouse: '南宁仓库',
          goods_type: '浆果',
          goods_no: 'P001',
          goods_name: '葡萄',
          model: '1.5kg',
          unit: '件',
          safe_stock: '20',
          system_stock: '10',
          check_stock: '',
          stock_surplus_losses: ''
        }
      ]
    }
  },

  created() {
    for(let i=0;i<this.tableData.length;i++){
      if(this.tableData[i].system_stock < this.tableData[i].safe_stock){
        this.$notify({
          title: '库存不足警告',
          message: '编号为'+this.tableData[i].goods_no+this.tableData[i].goods_name+'商品库存不足，请及时调整！',
          type: 'warning',
          duration: 0
        });
      }
    }
  },

  methods: {
    //搜索
    search() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log(this.form)
          this.$message.success('成功!');
        } else {
          console.log('error submit!!');
          this.$message.error('失败!');
          return false;
        }
      });
    },

    //每页条数改变时触发事件,选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pagesize = val;
    },
    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    }
  }
}
</script>
<style lang="scss">

</style>
